<?php
namespace app\serverfund\logic;

use \app\manage\logic\BaseLogic;

/**
 * @author:      李颖
 * @DateTime:    2017-07-03 16:49:12
 * @Description: 数字币冻结日志
 */
class CurrencyFreezeLog extends BaseLogic
{
    protected $name = 'currency_freeze_log';
    protected $config = 'db_config_fund';
    private $currencyFreezeLogModel = '\app\serverfund\model\CurrencyFreezeLog';

    // 所有用户数字币冻结日志分页数据
    public function list(array $data): array
    {
        $where['status'] = 1;
        $data['keywords'] && $where['user_id'] = ['like', '%' . $data['keywords'] . '%'];
        $data['type'] && $where['type'] = $data['type'];
        
        if($data['startTime']){
            $where['create_time'] = $data['endTime'] ? ['between', [$data['startTime'],$data['endTime']]] : ['egt', $data['startTime']];
        }else{
            $data['endTime'] && $where['create_time'] = ['elt', $data['endTime']];
        } 
        $res = $this->model($this->currencyFreezeLogModel)
                    ->where($where)
                    ->order('id desc')
                    ->paginate($data['list_rows'], false, ['page'=>$data['page']])
                    ->toArray();
        return auto_return_page($res, '已找到用户数字币冻结日志', '没有用户数字币冻结日志');
    }
    // 获取某些user_ids的的数字币冻结日志(分页)
    public function listByUserIds(array $data): array
    {
        $where['status'] = 1;
        $where['user_id'] = ['IN', $data['user_ids']];
        $res = $this->model($this->currencyFreezeLogModel)
                    ->where($where)
                    ->order('id desc')
                    ->paginate($data['list_rows'], false, ['page'=>$data['page']])
                    ->toArray();
        return auto_return_page($res, '已找到用户数字币冻结日志', '没有用户数字币冻结日志');
    }

    //获取某一条数字币冻结日志
    public function getOneInfo($data): array 
    {
        $_where['user_id'] = $data['user_id'];
        //注释47行的原因： 
        //在艺货app_id中用户A转让给用户B一个证书（在艺货中冻结A），但用户B可以在亚数app_id中同意（在亚数中解冻A），故限制app_id会找不到冻结日志记录
        //$_where['app_id'] = $data['app_id'];
        $_where['type'] = $data['type'];
        $_where['obj_id'] = $data['obj_id'];
        $_where['freeze_counts'] = $data['freeze_counts'];
        $_where['freeze_status'] = $data['freeze_status'];
        $_where['status'] = 1;

        $res = $this->model($this->currencyFreezeLogModel)
                    ->where($_where)
                    ->find();
        return auto_return($res);
    }

}